package org.prism.thread.tick;

public class SellTick01 extends Thread{
    //一共一百张票
    private static int ticket = 100;

    @Override
    public void run() {
        while (true){
            synchronized (SellTick01.class){
                if(ticket > 0){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "卖票: 票号" + ticket);
                    ticket--;
                }else{
                    break;
                }
            }
        }
    }
}

class SellTickTest01{
    public static void main(String[] args) {
        Thread t1 = new SellTick01();
        Thread t2 = new SellTick01();
        Thread t3 = new SellTick01();

        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();
    }


}
